<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:thSys="">
<div th:replace="admin/module/macros :: head('面试题管理')"></div>
<body class="app sidebar-mini rtl">
<main class="app-content">
    <div th:replace="admin/module/macros :: header"></div>
    <div th:replace="admin/module/macros :: sidebar"></div>
    <div class="app-title">
        <div>
            <h1>
                <i class="fa fa-book"></i>面试题管理
            </h1>
        </div>
        <ul class="app-breadcrumb breadcrumb">
            <li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
            <li class="breadcrumb-item"><a href="/admin/article">面试题管理</a></li>
            <li class="breadcrumb-item">所有面试题</li>
        </ul>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="tile">
                <div>
                    <form class="form-inline" role="form">
                        <div class="form-group col-md-2 col-*">
                            <label class="form-label ">标题：</label>
                            <input type="text" class="form-control" name="title">
                        </div>
                        <div class="form-group col-md-3 col-*">
                            <label class="form-label ">分类：</label>
                            <select name="category" id="category" class="form-control" style="width: 320px">
                                <optgroup>
                                    <option th:each="category:${categorys}"
                                            th:value="${category.categoryId}"
                                            th:text="${category.categoryName}"></option>
                                </optgroup>
                            </select>
                        </div>
                        <div class="form-group col-md-3 col-*">

                            <div class="col-md-1 col-*">
                                <button class="btn btn-outline-info" type="submit">查询</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="tile">
                <input type="hidden" id="articleId">
                <div class="table-responsive">
                    <table class="table table-striped table-bordered table-hover"
                           id="article_table">
                        <tr>
                            <td>面试题标题</td>
                            <td>所在分类</td>
                            <td>所在内部子分类</td>
                            <td>标签</td>
                            <td>创建时间</td>
                            <td>操作</td>
                        </tr>
                        <tr th:each="article,iterStat : ${info.list}">
                            <td th:text="${#strings.abbreviate(article.articleTitle,60)}" class="mt-auto"></td>
                            <td th:text="${#strings.abbreviate(article.categorysName,20)}"></td>
                            <td th:text="${#strings.abbreviate(article.subCategoryName,20)}"></td>
                            <td th:text="${#strings.abbreviate(article.tagsName,20)}"></td>
                            <td
                                    th:text="${#dates.format(article.articleNewstime,'yyyy/MM/dd HH:mm:ss')}"></td>
                            <td th:switch="${article.articleStatus}">
                                <th:block
                                        th:case="0">
                                    <a th:href="@{'/question/'+${article.articleUrl}}"
                                       th:target="_blank" class="btn btn-outline-primary btn-sm">查看</a>
                                    <a th:href="@{/admin/question/edit(article_id=${article.id})}"
                                       class="btn btn-outline-info btn-sm">编辑</a>
                                    <button
                                            th:onclick="'javascript:recycleModel('+${article.id}+')'"
                                            class="btn btn-outline-danger btn-sm">丢弃
                                    </button>
                                </th:block>
                                <th:block th:case="1">
                                    <a th:href="@{/admin/article/edit(article_id=${article.id})}"
                                       class="btn btn-outline-primary btn-sm">编辑</a>
                                    <button th:onclick="'javascript:restore('+${article.id}+')'"
                                            class="btn btn-outline-info btn-sm">发布
                                    </button>
                                    <button
                                            th:onclick="'javascript:recycleModel('+${article.id}+')'"
                                            class="btn btn-outline-danger btn-sm">丢弃
                                    </button>
                                </th:block>
                                <th:block th:case="2">
                                    <button th:onclick="'javascript:restore('+${article.id}+')'"
                                            class="btn btn-outline-primary btn-sm">还原
                                    </button>
                                    <button th:onclick="'javascript:showModel('+${article.id}+')'"
                                            class="btn btn-outline-danger btn-sm">彻底删除(不可逆)
                                    </button>
                                </th:block>
                            </td>
                        </tr>
                        <tr th:unless="${info.list.total} != 0">
                            <td th:text="暂无面试题" th:attr="colspan='7',align='center'"></td>
                        </tr>
                    </table>
                </div>
                <div th:replace="admin/module/macros :: pageQuestion(${info}, ${url})"></div>
            </div>
        </div>
    </div>
</main>
<div th:replace="admin/module/macros :: remove"></div>
<div th:replace="admin/module/macros :: recycle"></div>
<div th:replace="admin/module/macros :: comm"></div>
<script src="/plugins/select2/select2.min.js"></script>
<script type="text/javascript">


    function recycleModel(id) {
        $("#articleId").val(id);
        $("#recycleModal").modal();
    }

    function recycle() {
        window.location.href = "/admin/article/recycle?id="
            + $("#articleId").val();
    }

    function showModel(id) {
        $("#articleId").val(id);
        $("#removeModal").modal();
    }

    function remove() {
        window.location.href = "/admin/article/remove?id="
            + $("#articleId").val();
    }

    function restore(id) {
        $.ajax({
            url: "/admin/article/restore",
            type: "post",
            data: {
                id: id
            },
            dataType: "json",
            success: function (data) {
                if (data.flag == true) {
                    window.location.reload();
                } else {
                    showMsg(data.msg, "error", "3000");
                }
            }
        });
    }

    $('#category').select2();
</script>
</body>
</html>